<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<script>
    // 定义对象（属性+函数）
    var stu = {
        id:1001,
        name:"zhangsan",
        age:23,
        addr:"回龙观",
        likes:["体育","音乐","电影"],
        print:function (){
            console.log("打印属性：");
            console.log("id:"+this.id);
            console.log("name:"+this.name);
            console.log("addr:"+this.addr);
            for (let i = 0; i < this.likes; i++) {
                console.log("爱好:"+this.likes[i]);
            }
        },
        send:function (){
            console.log("发送给服务器");
        },
        validate:function (){
            // 验证数据的有效性
            if(!this.name){
                console.log("名称不能为空")
                return false;
            }
            if(this.name.length < 5){
                console.log("长度不能小于5个长度")
                return false;
            }
            return true;
        }
    };
    var age = 23;
    console.log(typeof stu.id);
    console.log(stu.name);
    console.log(stu.likes);
    // 调用方法打印
    stu.print();
    stu.name = "san";
    if(stu.validate()){
        stu.send();
    }


    // var person = {
    //     name : "zhangsan",
    //     age : 23,
    //     eat: function (){
    //         alert("干饭~");
    //     }
    //
    // };
    //
    //
    // alert(person.name);
    // alert(person.age);
    //
    // person.eat();



</script>
</body>
</html>